import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';

@Global()
@Module({
	imports: [
		TypeOrmModule.forRootAsync({
			imports : [ConfigureModule],
			inject : [ConfigureService],
			useFactory : (config:ConfigureService) => {
				
				return {
					...config.get<TypeOrmModuleOptions>('db')
				}
			},
		}),

		SysConfigRepositoryModule,
	],
	providers: [DbService],
	exports: [DbService]
})
export class DbModule {}
